package com.wmh.baseservice.operationaid.controller;

import com.alibaba.fastjson2.JSON;
import com.wmh.baseservice.operationaid.enums.FeatureType;
import com.wmh.baseservice.operationaid.pojo.vo.FeatureParamTemplate.CommitReqVO;
import com.wmh.baseservice.operationaid.service.FeatureParamTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import static com.wmh.baseservice.common.utils.returnbody.ReturnBody.success;

/**
 * @author 谢骏
 * @date 2023/7/3 15:07
 **/
@Validated
@RestController
@RequestMapping("operationAid/featureParamTemplate")
@Api(tags = "关键词助手-功能参数模板")
public class FeatureParamTemplateController {

    @Resource
    private FeatureParamTemplateService featureParamTemplateService;

    @ApiModelProperty(value = "提交模板")
    @PostMapping("/commit")
    public String commit(@Valid CommitReqVO reqVo) {
        return success(featureParamTemplateService.commit(reqVo));
    }

    @ApiModelProperty(value = "删除")
    @PostMapping("/delete")
    public String delete(
            @NotBlank(message = "未提交主键")
            @Size(min = 3, message = "未提交主键")
            String jsonIds) {
        featureParamTemplateService.delete(JSON.parseArray(jsonIds,Long.class));
        return success();
    }

    @ApiModelProperty(value = "表格信息")
    @PostMapping("/table")
    public String table(@NotNull FeatureType type) {
        return success(featureParamTemplateService.table(type));
    }
}
